//
// Created by bangsun on 2022/10/15.
//

#ifndef SWITCHTEST_LINKED_LIST_H
#define SWITCHTEST_LINKED_LIST_H


typedef int node_id;

struct round_list {
    struct ll_node *cur;
    int total;
};

struct ll_node {
    struct ll_node *prev, *next;
    node_id id;
    void *val;
};

typedef struct round_list round_list;
typedef struct ll_node ll_node;


typedef struct {
    int capacity;
    round_list alive, dead;
    ll_node **lookUpMap;
} sized_node_pool;




void init_round_list(round_list *roundList);

void destroy_round_list(round_list *roundList);

ll_node *insert_node(round_list *roundList, void *val);

ll_node *insert_directly(round_list *roundList, ll_node *node);

ll_node *delete_node(round_list *list, node_id id);

ll_node *delete_directly(round_list *list, ll_node *node);

ll_node *poll_node(round_list *list);


void init_sized_node_pool(sized_node_pool *nodePool, int capacity);

void reset_size(sized_node_pool *nodePool, int newSize);

void *pool_get_node(sized_node_pool *nodePool, node_id id);

void pool_insert_node(sized_node_pool *nodePool, node_id *tid, void *val);

void pool_delete_node(sized_node_pool *nodePool, node_id tid, void(*val_destroyer)(void *));

void pool_destroy_node(sized_node_pool *nodePool, node_id tid, void(*val_destroyer)(void *));


void *pool_iter_node(sized_node_pool *pool, int exception);


#endif //SWITCHTEST_LINKED_LIST_H
